package com.ruoyi.classai.controller;

import java.util.Arrays;
import java.util.List;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.classai.domain.EwcGroupingStrategyCode;
import com.ruoyi.classai.service.IEwcGroupingStrategyCodeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 分组策略代码Controller
 * 
 * @author lcj
 * @date 2025-02-28
 */
@RestController
@RequestMapping("/code")
public class EwcGroupingStrategyCodeController extends BaseController
{
    @Autowired
    private IEwcGroupingStrategyCodeService ewcGroupingStrategyCodeService;

    /**
     * 查询分组策略代码列表
     */
    @RequiresPermissions("classai:code:list")
    @GetMapping("/list")
    public TableDataInfo list(EwcGroupingStrategyCode ewcGroupingStrategyCode)
    {
        startPage();
        List<EwcGroupingStrategyCode> list = ewcGroupingStrategyCodeService.list(Wrappers.query(ewcGroupingStrategyCode));
        return getDataTable(list);
    }

    /**
     * 导出分组策略代码列表
     */
    @RequiresPermissions("classai:code:export")
    @Log(title = "分组策略代码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EwcGroupingStrategyCode ewcGroupingStrategyCode)
    {
        List<EwcGroupingStrategyCode> list = ewcGroupingStrategyCodeService.list(Wrappers.query(ewcGroupingStrategyCode));
        ExcelUtil<EwcGroupingStrategyCode> util = new ExcelUtil<EwcGroupingStrategyCode>(EwcGroupingStrategyCode.class);
        util.exportExcel(response, list, "分组策略代码数据");
    }

    /**
     * 获取分组策略代码详细信息
     */
    @RequiresPermissions("classai:code:query")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ewcGroupingStrategyCodeService.getById(id));
    }

    /**
     * 新增分组策略代码
     */
    @RequiresPermissions("classai:code:add")
    @Log(title = "分组策略代码", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody EwcGroupingStrategyCode ewcGroupingStrategyCode)
    {
        return toAjax(ewcGroupingStrategyCodeService.save(ewcGroupingStrategyCode));
    }

    /**
     * 修改分组策略代码
     */
    @RequiresPermissions("classai:code:edit")
    @Log(title = "分组策略代码", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody EwcGroupingStrategyCode ewcGroupingStrategyCode)
    {
        return toAjax(ewcGroupingStrategyCodeService.updateById(ewcGroupingStrategyCode));
    }

    /**
     * 删除分组策略代码
     */
    @RequiresPermissions("classai:code:remove")
    @Log(title = "分组策略代码", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ewcGroupingStrategyCodeService.removeByIds(Arrays.asList(ids)));
    }
}
